//
//  UserViewController.m
//  UI_元旦豆瓣
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 31付冬梅. All rights reserved.
//

#import "UserViewController.h"
#import "LTView.h"
#import "UserViewController2.h"
#import "UserViewController3.h"
#import "SecondViewController.h"
#import "AfraDataBase--MovieActivity.h"
@interface UserViewController ()<UITableViewDataSource, UITableViewDelegate, StrDelegate>
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSString *itemTitle;
@end

@implementation UserViewController
- (void)string {
    self.navigationItem.rightBarButtonItem.title = @"注销";
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    self.title = @"我的";
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"注销" style:UIBarButtonItemStylePlain target:self action:@selector(itemAction:)];
    self.navigationItem.rightBarButtonItem = item;
    
    
    
    }
//点击cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    SecondViewController *secVc = [[SecondViewController alloc] init];
    if (indexPath.row == 0) {
        secVc.str = @"我的活动收藏";
    }
    if (indexPath.row == 1) {
        secVc.str = @"我的电影收藏";
    }
    if (indexPath.row == 2) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"注销" message:@"是否确定注销" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [[AfraDataBase__MovieActivity sharedInstenceDataBaseHandle] deleteAllModel];
   
        }];
        UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        [alert addAction:action1];
        [alert addAction:action2];
        [self presentViewController:alert animated:YES completion:^{
            
        }];
    }
    
    [self.navigationController pushViewController:secVc animated:YES];
    
}
- (void)itemAction:(UIBarButtonItem *)item {
   
    if ([self.navigationItem.rightBarButtonItem.title isEqualToString:@"注册"]) {
        UserViewController2 *view2 = [[UserViewController2 alloc] init];
        view2.str = @"注销";
        self.navigationItem.rightBarButtonItem.title = view2.str;
        [self presentViewController:view2 animated:YES completion:^{
            
        }];
    } else {
        
        UIAlertController *alert1 = [UIAlertController alertControllerWithTitle:@"提示" message:@"您是否要注销" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            self.navigationItem.rightBarButtonItem.title = @"注册";
        }];
        UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        [alert1 addAction:action1];
        [alert1 addAction:action2];
        [self presentViewController:alert1 animated:YES completion:^{
            
        }];
    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (indexPath.row == 0) {
        cell.textLabel.text = @"我的活动";
        
    }
    if (indexPath.row == 1) {
        cell.textLabel.text = @"我的收藏";
    }
    if (indexPath.row == 2) {
        cell.textLabel.text = @"清除缓存";
    }
    return cell;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
